package org.jeecg.modules.analysisachievement.reports.service.impl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.data.Rows;
import com.deepoove.poi.data.TableRenderData;
import com.deepoove.poi.data.Tables;
import com.deepoove.poi.data.style.BorderStyle;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;

import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.analysisachievement.reports.service.IDataList2TableUtilService;
import org.jeecg.modules.common.api.IRow2ColTransfer;
import org.jeecg.modules.common.baseentity.Row2ColModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DataList2TableUtilService implements IDataList2TableUtilService {
    @Autowired
    private IRow2ColTransfer row2ColTransfer;

    /**
     * 返回二维表格数据，按行转列后的结果显示
     * @param dataList
     * @param row2ColModel
     * @return
     * @throws NoSuchFieldException
     * @throws IllegalAccessException
     */
    public  TableRenderData getTableByDataListForRow2Col(List dataList, Row2ColModel row2ColModel)throws NoSuchFieldException, IllegalAccessException{
        if(oConvertUtils.listIsEmpty(dataList) || oConvertUtils.isEmpty(row2ColModel) || oConvertUtils.isEmpty(row2ColModel.getGroupFields())  ){
            return null;
        }
        return Tables.of(row2ColTransfer.Row2ColTo2DArray(dataList,  row2ColModel)).border(BorderStyle.DEFAULT).create();
    }

}
